﻿using Admin.Crypto.Session;
using System.Security.Claims;

namespace Admin.Crypto.Runtime
{
    /// <summary>
    /// aspnet core 基于声明主体访问实现
    /// </summary>
    public class AspNetCorePrincipalAccessor : DefaultPrincipalAccessor
    {
        /// <summary>
        /// 获取声明主体
        /// </summary>
        public override ClaimsPrincipal Principal => _httpContextAccessor.HttpContext?.User ?? base.Principal;

        private readonly IHttpContextAccessor _httpContextAccessor;

        /// <summary>
        /// aspnet core 基于声明主体访问实现
        /// </summary>
        /// <param name="httpContextAccessor"></param>
        public AspNetCorePrincipalAccessor(IHttpContextAccessor httpContextAccessor)
        {
            _httpContextAccessor = httpContextAccessor;
        }
    }
}
